<?php

namespace app\home\controller;

use app\home\model\MerchantModel;

use app\Request;
use think\exception\ValidateException;
use ulit\CryptAES;

class Member extends MeberBase
{




    public function list(){



        return view();
    }

    public function ajaxlist(): \think\response\Json
    {



        $result=MerchantModel::merchantList();

        return $this->success($result);

    }

    public function addEdit(Request $request){


        $id= input('id');
        if($request->isPost() && $request->isAjax()){

            $id= input('id');

                $result= MerchantModel::edit($id);
                return $this->result($result);

        }
        $info=MerchantModel::where(['id'=>$id])->find();


        return view('member/addEdit',['info'=>$info]);
    }


    public function modifyPassword(Request $request ): \think\response\View|\think\response\Json
    {
        $info= \app\admin\model\merchant\MerchantModel::where(['id'=>input('id')])->find();
        if($request->isPost() && $request->isAjax()){
            $aes=new CryptAES();
            try {
                $add=input('');
                $result = validate(\app\admin\validate\merchant\Merchant::class)->scene('ModifyPassword')->check($add);
                if(!empty($result)){
                    $password=$aes->aesEncode(input('password'));
                    MerchantModel::where(['id'=>input('id')])->update(['password'=>$password]);
                    return $this->success();
                    // dump($result);die;
                }
            } catch (ValidateException $e) {
                // 验证失败 输出错误信息
                return $this->result($e->getError());
            }
        }
        return view('member/modify_password',['info'=>$info]);
    }



}